package cn.tju.yanbo.commons;

import android.graphics.Point;
import android.graphics.Rect;
import android.view.MotionEvent;
import android.widget.ImageView;
import cn.tju.yanbo.R;
import cn.tju.yanbo.utils.AppConfig;
import cn.tju.yanbo.utils.AppUtils;

public class SettingViewListener extends LayoutViewGestureListener {

    private ImageView [] viewList = new ImageView[AppConfig.SETTING_CHOICE_RADIO_TOTAL];
    private Rect [] boundsList = new Rect[AppConfig.SETTING_CHOICE_RADIO_TOTAL];
    
    public SettingViewListener(BaseActivity activity) {
        super(activity);
        viewList[0] = (ImageView)activity.findViewById(R.id.show_page_radio_box);
        viewList[1] = (ImageView)activity.findViewById(R.id.voice_adjust_radio_box);
        viewList[2] = (ImageView)activity.findViewById(R.id.vibration_adjust_radio_box);
    }

    @Override
    public boolean onSingleTapUp(MotionEvent e) {
        
        boundsList[0] = new Rect(viewList[0].getLeft(), viewList[0].getTop(), viewList[0].getRight(), viewList[0].getBottom());
        boundsList[1] = new Rect(viewList[1].getLeft(), viewList[1].getTop(), viewList[1].getRight(), viewList[1].getBottom());
        boundsList[2] = new Rect(viewList[2].getLeft(), viewList[2].getTop(), viewList[2].getRight(), viewList[2].getBottom());
        
        int index = AppUtils.touchOnWhichBounds(new Point((int)e.getX(), (int)e.getY()), boundsList);
        if(index!=-1) {
            for(int i=0; i<viewList.length; i++) {
                ImageView iv = viewList[i];
                if(i!=index) iv.setImageDrawable(activity.CACHED_PICTURES.get(R.drawable.choose_botton));
                else iv.setImageDrawable(activity.CACHED_PICTURES.get(R.drawable.choose_botton_red));
            }
            return true;
        }
        return false;
    }
}

